package com.sgb.knowledgeshare.view.activity;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.sgb.knowledgeshare.R;
import com.sgb.knowledgeshare.databinding.ActivityShareVideoPlayUserInfoBinding;
import com.sgb.knowledgeshare.utils.RxBus;
import com.sgb.knowledgeshare.utils.VideoPlayListEvent;
import com.sgb.knowledgeshare.view.fragment.ShareVideoPlayListFragment;
import com.sgb.knowledgeshare.view.fragment.ShareVideoPlayUserFragment;
import com.swgk.core.base.AppActivity;
import com.swgk.core.base.model.entity.VideoBean;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;
import java.util.ArrayList;
import java.util.List;

import rx.functions.Action1;

/**
 * Created by fq on 2020/9/11 0011
 * Description： 分享模块点击单个视频跳转的视频播放及向左滑动展示用户信息通用类
 */
public class VideoPlayUserInfoActivity extends AppActivity {


    private ActivityShareVideoPlayUserInfoBinding binding;
    private ArrayList<Fragment> fragments;
    private String type;
    private List<VideoBean> bean;

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_share_video_play_user_info);
        type = getIntent().getStringExtra("type");
        bean = (List<VideoBean>) getIntent().getSerializableExtra("bean");
        binding.videoplayUserinfoViewpager.setNoScroll(true);
        fragments = new ArrayList<>();
        fragments.add(ShareVideoPlayListFragment.newInstance(type,getIntent().getIntExtra("pos", 0),bean));
        fragments.add(ShareVideoPlayUserFragment.newInstance(bean.get(getIntent().getIntExtra("pos", 0)).getCreateUser()));
        SlidingFragmentPagerAdapter mAdapetr = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), fragments);
        binding.videoplayUserinfoViewpager.setAdapter(mAdapetr);
        //点击头像切换页面
        RxBus.getDefault().toObservable(VideoPlayListEvent.class)
                .subscribe((Action1<VideoPlayListEvent>) event -> {
                    if (binding.videoplayUserinfoViewpager != null) {
                        binding.videoplayUserinfoViewpager.setCurrentItem(event.getPage());
                    }
                });
        binding.videoplayUserinfoViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

}
